package com.cyh.forum.controller;

import com.cyh.forum.common.AppResult;
import com.cyh.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;


@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1: 显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw  new Exception("这是一个 exception");
    }

    @ApiOperation("测试接口2: 显示自定义的异常信息")
    @GetMapping("/appException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个自定义的 ApplicationException");
    }

    @ApiOperation("测试接口3:按传入的信息显示你好xx")
    @PostMapping("/helloByName")
    public String helloByName(@ApiParam("要传入的姓名") @RequestParam("name") String name){
        return "hello: "+ name;
    }
}
